#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>

void SelectSort(int* a, int n)
{
	int begin = 0, end = n - 1;
	while (begin < end)
	{

		int min = end, max = begin;

		for (int i = begin; i <=end; i++)
		{
			if (a[i] > a[min])
			{
				min = i;
			}
			if (a[i] < a[max])
			{
				max = i;
			}
		}
		int temp = a[begin];
		a[begin] = a[min];
		a[min] = temp;
		int temp1 = a[end];
		a[end] = a[max];
		a[max] = temp1;
		begin++;
		end--;
	}
	for (int i = 0; i < n; i++)
	{
		printf("%d ", a[i]);
	}
}
void TestSelectSort()
{
	int a[] = { 9,3,5,1,2,6,8,0,4,7 };
	SelectSort(a, sizeof(a) / sizeof(a[0]));
}
int main()
{
	TestSelectSort();
	return 0;
}